home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11409 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  34 lines

  1. Path: news1.is.net!news
  2. From: Mark VanTassel <mvantassel@teambca.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Lifetime of temporary parameter objects
  5. Date: Thu, 14 Mar 1996 09:06:57 -0500
  6. Organization: Barfield, Cauthen and Associates
  7. Message-ID: <31482801.ABF@teambca.com>
  8. References: <4i6607$l4q@damon.irf.uni-dortmund.de>
  9. NNTP-Posting-Host: dynamic28.is.net
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (Win95; I)
  14.  
  15. Bernd Rothert wrote:
  16.  
  17. > void banner(const Stars& st, const char* s) {
  18. >                            //=============
  19. >     cout << st.get() << endl << s << endl;
  20. > }
  21. > int main() {
  22. >     banner(40, Stars(40).get());
  23. >              //===============
  24. >     return 0;
  25. > }
  26.  
  27. This looks OK to me... the explicitly-constructed object, like all temporaries, 
  28. remains in scope until the end of the statement it is in. Of course, 'banner' 
  29. can't just stash the pointer away for later - it'll point to garbage then - but 
  30. using cout as shown is fine.
  31.  
  32. BTW, you might consider a (const char *) cast operator, instead of a "get()" 
  33. method.
  34.